var crypto = require('../modules/cryptoUtility');

exports.test = function(req, res, next) {
	res.locals.filter = "from filter test";
	next();
}

exports.authorize = function(req, res, next) {
	if(req.cookies.user)
	{ 
	    console.log('usecookies-cookies:', req.cookies.user);
	    req.session.user = req.cookies.user;
	}  
	if(req.session.user){
		console.log('usecookies:', req.session.user);
    	res.locals.user = JSON.parse(crypto.DecryptDES(req.session.user));    	
	}

	if (!req.session.user) {
		//res.redirect('/login');
		res.locals.user = "";
		next();
	} else {
		next();
	}
}
